const formidable = require('formidable')
const path = require('path');
const { Article } = require('../../model/article')
module.exports = (req, res) => {
    //创建表单解析对象
    const form = new formidable.IncomingForm();
    //创设置文件上传路径
    form.uploadDir = path.join(__dirname, '../', '../', 'public', 'admin', 'uploads');
    form.keepExtensions = true;
    form.parse(req, async(err, fields, files) => {


        await Article.create({
            title: fields.title,
            author: fields.author,
            publishDate: fields.publishDate,
            cover: files.cover.path.split('public')[1],
            content: fields.content
        })
        res.redirect('/admin/article')

    })

}